/**
 * All files in the shared package will be used by both the server and the client.
 * These will be copied to both projects when deploying.
 * 
 * Belongs to package: core
 */
package llama.core;

/**
 * A contact combines a <code>User</code> object with a tag.
 */
public class Contact {

	private IUser user;
	private String tag;
	
	@Deprecated
	public Contact() {
		
	}
	
	/**
	 * Creates a contact.<br>
	 * If either the user parameter or the tag parameter is null {@link IllegalArgumentException} is thrown.
	 * @param user the user that's going to be the contact, can't be null.
	 * @param tag the tag assigned to this contact, can't be null.
	 */
	public Contact(IUser user, String tag) {
		if(user == null || tag == null) {
			throw new IllegalArgumentException("");
		}
		this.user = user;
		this.tag = tag;
	}
	
	public IUser getUser() {
		return user;
	}
	
	public String getTag() {
		return tag;
	}
	
	public void setTag(String tag) {
		this.tag = tag;
	}
	
	/**
	 * A contact is equal to another contact when the user-object is equal to that of the other.
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof Contact) {
			return user.equals(((Contact) obj).getUser());	
		}
		return false;
	}
	
	/**
	 * A contact has the same hashCode as the User-object it holds.
	 */
	@Override
	public int hashCode() {
		return user.hashCode();
	}
	
}
